﻿using FrontEnd.Application.MembershipFacade;
using FrontEnd.Controllers;
using FrontEnd.Models;
using Microsoft.Practices.Unity;

namespace UnitTests.Controllers.Membership
{
    internal class TestEnvironment
    {

		public TestEnvironment()
        {
            this.Membership = new StubMembershipFacade();
            this.Container = new UnityContainer();
            this.Container.RegisterInstance<IMembershipFacade>(this.Membership);
        }

        public StubMembershipFacade Membership
        {
            get;
            private set;
        }

        public IUnityContainer Container
        {
            get;
            private set;
        }           

        public MembershipController Build()
        {
            return this.Container.Resolve<MembershipController>();
        }

        public void AddFakeAccount(string email, string password)
        {
            AccountInfo account =
                new AccountInfo
                {
                    Id = email,
                    Person =
                        new PersonInfo
                        {
                            EmailAddress = email,
                            DisplayName = email
                        }
                };

            this.Membership.AddAccount(account, password);
        }
    }
}
